#include "btform.h"
#include "ui_btform.h"

BtForm::BtForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BtForm)
{
    ui->setupUi(this);

    //设置line1的动画效果
    line1Animation = new QPropertyAnimation(ui->line1, "geometry", this);
    line1Animation->setDuration(1500);
    line1Animation->setKeyValueAt(0, QRect(4, 15, 2, 0));
    line1Animation->setKeyValueAt(0.5, QRect(4, 0, 2, 15));
    line1Animation->setKeyValueAt(1, QRect(4, 15, 2, 0));
    line1Animation->setLoopCount(-1);
    line1Animation->start();

    //设置line2的动画效果
    line2Animation = new QPropertyAnimation(ui->line2, "geometry", this);
    line2Animation->setDuration(1600);
    line2Animation->setKeyValueAt(0, QRect(10, 15, 2, 0));
    line2Animation->setKeyValueAt(0.5, QRect(10, 0, 2, 15));
    line2Animation->setKeyValueAt(1, QRect(10, 15, 2, 0));
    line2Animation->setLoopCount(-1);
    line2Animation->start();

    //设置line3的动画效果
    line3Animation = new QPropertyAnimation(ui->line3, "geometry", this);
    line3Animation->setDuration(1700);
    line3Animation->setKeyValueAt(0, QRect(16, 15, 2, 0));
    line3Animation->setKeyValueAt(0.5, QRect(16, 0, 2, 15));
    line3Animation->setKeyValueAt(1, QRect(16, 15, 2, 0));
    line3Animation->setLoopCount(-1);
    line3Animation->start();

    //设置line4的动画效果
    line4Animation = new QPropertyAnimation(ui->line4, "geometry", this);
    line4Animation->setDuration(1800);
    line4Animation->setKeyValueAt(0, QRect(22, 15, 2, 0));
    line4Animation->setKeyValueAt(0.5, QRect(22, 0, 2, 15));
    line4Animation->setKeyValueAt(1, QRect(22, 15, 2, 0));
    line4Animation->setLoopCount(-1);
    line4Animation->start();

    //默认动画为隐藏
    ui->lineBox->hide();

}

BtForm::~BtForm()
{
    delete ui;
}

void BtForm::setIconAndText(const QString &icon, const QString &text, int pageId)
{
    //设置图标
    ui->btIcon->setPixmap(icon);

    //设置文本
    ui->btText->setText(text);

    //关联主界面中的page页
    this->pageId = pageId;
}

int BtForm::getPageId()
{
    return pageId;
}

void BtForm::clearBackGround()
{
    //清除背景颜色
    ui->btStyle->setStyleSheet("#btStyle:hover{background-color:#d8d8d8}");

    //清除动画
    ui->lineBox->hide();
}

void BtForm::showStyle()
{
    ui->btStyle->setStyleSheet("#btStyle{background-color:rgb(30, 206, 154);}");

    //设置动画
    ui->lineBox->show();
}

void BtForm::mousePressEvent(QMouseEvent *event)
{
    (void)event;
    //当按钮被按下,改变背景样式
    showStyle();

    //切换bodyRight中的page页
    emit btClick(pageId);
}

void BtForm::mouseMoveEvent(QMouseEvent *event)
{
    (void)event;
}
